package com.ch.home.controller.userController;

import com.ch.home.bean.UserComment;
import com.ch.home.service.serviceImpl.userServiceImpl.UserCommentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;

/**
 * Created by CHEN on 2019/8/17.
 */
@RestController
public class UserCommentController {

    @Autowired
    UserCommentServiceImpl userCommentServiceImpl;


    @PostMapping("/commemt/add")
    public HashMap insertUserComment(@RequestParam(required = false)Integer commentId,
                                     @RequestParam(required = false)Integer userId,
                                     @RequestParam(required = false)Integer foreignId,
                                     @RequestParam(required = false)Integer parentCommentId,
                                     @RequestParam(required = false)Date time,
                                     @RequestParam(required = false)String content,
                                     @RequestParam(required = false)Integer likeNum,
                                     @RequestParam(required = false)Integer status) {

        UserComment userComment = new UserComment(commentId,userId,foreignId,parentCommentId,time,content,likeNum,status,0);
        HashMap result = userCommentServiceImpl.insertUserComment(userComment);
        return result;
    }


    @PostMapping("/commemt/getByCommentId")
    public HashMap selectByCommentId(@RequestParam(required = false)Integer commentId) {
        HashMap result = userCommentServiceImpl.selectByCommentId(commentId);
        return result;
    }

    @PostMapping("/commemt/getById")
    public HashMap selectById(@RequestParam(required = false)Integer commentId,
                              @RequestParam(required = false)Integer userId,
                              @RequestParam(required = false)Integer foreignId,
                              @RequestParam(required = false)Integer parentCommentId,
                              @RequestParam(required = false)Date time,
                              @RequestParam(required = false)String content,
                              @RequestParam(required = false)Integer likeNum,
                              @RequestParam(required = false)Integer status) {
        UserComment userComment = new UserComment(commentId,userId,foreignId,parentCommentId,time,content,likeNum,status,0);
        HashMap result = userCommentServiceImpl.selectByUserId(userComment);
        return result;
    }

    @PostMapping(value="/comment/likeOrDelete")
    public HashMap likeOrDelete(@RequestParam(required = false)Integer commentId,
                                @RequestParam(required = false)Integer userId,
                                @RequestParam(required = false)Integer foreignId,
                                @RequestParam(required = false)Integer parentCommentId,
                                @RequestParam(required = false)Date time,
                                @RequestParam(required = false)String content,
                                @RequestParam(required = false)Integer likeNum,
                                @RequestParam(required = false)Integer status) {
        UserComment userComment = new UserComment(commentId,userId,foreignId,parentCommentId,time,content,likeNum,status,0);
        HashMap result = userCommentServiceImpl.updateUser(userComment);
        return result;
    }
    //application/json格式可以接，表单不能接
//    @PostMapping(value="/comment/likeOrDelete2")
//    public HashMap likeOrDelete2(@RequestBody HashMap<Object,Object> map) {
//        UserComment userComment = userCommentService.getUserCommentFromMap(map);
//        HashMap result = userCommentService.updateUser(userComment);
//        return result;
//    }

}
